package org.kineticsproject.application.util;

import java.io.File;
import java.io.IOException;
import java.util.Iterator;

import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;

import data.DataPackage;
import data.Exercise;
import data.Person;
import data.Population;

public class EnumeratePopulation {

	/**
	 * @param args
	 */
	public static void main(String[] args) throws IOException {
		DataPackage dataPackage = DataPackage.eINSTANCE;
		
		//Create new ResourceSet & Resource
		ResourceSet resourceSet = new ResourceSetImpl();
		
		// Register XML resource factory
		resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xmi", 
		new XMIResourceFactoryImpl());

		Resource resource = resourceSet.createResource(URI.createFileURI(new File("myPopulation.xmi").getAbsolutePath()));

		// register package in local resource registry
		resourceSet.getPackageRegistry().put(dataPackage.getNsURI(), dataPackage);
		// load resource 
		resource.load(null);
		
	
		Population population = (Population)resource.getContents().get(0);
		
		Iterator<Person> it = population.getPeople().iterator();
		
		while(it.hasNext())
		{
			Person person = it.next();
			System.out.println("Name: "+person.getName());
			System.out.println("Height: "+person.getHeight());
			System.out.println("Weight: "+person.getWeight());
			System.out.println("Birth Date: "+person.getDateOfBirth());
			int i = 0;
			Iterator<Exercise> itex = person.getExercises().iterator();
			while(itex.hasNext())
			{
				Exercise ex = itex.next();
				System.out.println("Exercise"+i+": "+ex.getName());
				i++;
			}
			
			System.out.println();
		}
		

	}

}